package com.tl.sun.ui.adapter;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tl.sun.R;
import com.tl.sun.model.IpModelEntity;
import com.tl.sun.utils.common.TimeUtils;

import java.util.List;

/**
 * 作者：HQY on 17/8/9 09:10
 * 邮箱：hqy_xz@126.com
 */

public class IpModelAdapter extends BaseQuickAdapter<IpModelEntity, BaseViewHolder> {


    public IpModelAdapter(List<IpModelEntity> data) {
        super(R.layout.item_ip_model, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, IpModelEntity item) {
        ImageView mIvCollect = helper.getView(R.id.iv_model_collect);
        ImageView mIvMore = helper.getView(R.id.iv_model_more);
        TextView mTvNote = helper.getView(R.id.tv_model_note);
        LinearLayout mLlIpTime = helper.getView(R.id.ll_ip_time);

        helper.setText(R.id.tv_model_note, item.getRemark().equals("0") ? "" : item.getRemark())
                .setText(R.id.tv_model_ip, item.getMark())
                .setText(R.id.tv_model_address, item.getRegion() + "  " + item.getCity())
                .setText(R.id.tv_model_expire, item.getMarkExpireTime())
                .setText(R.id.tv_model_time,
                        item.getUpdateTime() > 0 ? TimeUtils.milliseconds2String(Long.valueOf(item.getUpdateTime()) * 1000, TimeUtils.DEFAULT_THTREE) : "暂无使用")
                .addOnClickListener(R.id.iv_model_more)
                .addOnClickListener(R.id.rl_model_collect)
                .addOnClickListener(R.id.tv_model_note);

        if (item.getIsCollect() == 1) {
            Drawable drawable = mContext.getResources().getDrawable(R.drawable.line_model_note);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            mTvNote.setCompoundDrawables(null, null, drawable, null);
            mIvCollect.setSelected(true);
        } else {
            mIvCollect.setSelected(false);
        }
        if (item.isShow()) {
            mLlIpTime.setVisibility(View.VISIBLE);
            Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.translate_star);
            mLlIpTime.startAnimation(animation);
            mIvMore.setEnabled(false);
        } else {
            mIvMore.setEnabled(true);
            mLlIpTime.setVisibility(View.GONE);
        }

    }
}
